package com.cgw.web.room.action;

import java.util.List;

import com.cgw.common.base.BaseAction;
import com.cgw.dmplt.common.PageBean;
import com.cgw.dmplt.room.dao.BuildingDao;
import com.cgw.dmplt.room.domain.Building;

public class BulidingAction extends BaseAction {

	private Building build;
	
	private PageBean<Building> page;
	private Integer buildId;

	
	public String doList(){
		BuildingDao buildDao=(BuildingDao)getBean("buildingDao");
		try{
			if(build==null){
				build=new Building();
			}
			List<Building> roomList=buildDao.listBuilding(build);
			
			Integer count=buildDao.listBuildingCount(build);
			
			page=new PageBean(roomList,count,build.getCurentPage());
			
		}catch(Exception e){
			log.error("列表查询出错!", e);
		}
		return SUCCESS;
	}
	
	public String doQuery(){
		BuildingDao buildDao=(BuildingDao)getBean("buildingDao");
		build=buildDao.findBuilding(buildId);
		return SUCCESS;
	}
	
	
	
	public String doDetail(){
		return doQuery();
	}
	
	public String doUpdate(){
		BuildingDao buildDao=(BuildingDao)getBean("buildingDao");
		
		buildDao.updateBuilding(build);
		
		return doList();
	}
	
	
	public String doInsert(){
		System.out.println("--------------do Insert..............."+build.getDecorate());
		BuildingDao buildDao=(BuildingDao)getBean("buildingDao");
		buildDao.insertBuilding(build);
		return doList();
	}
	

	
	public String doDelete(){
		BuildingDao buildDao=(BuildingDao)getBean("buildingDao");
		buildDao.deleteBuilding(build);
		
		build.clear(build.getClass(), build);
		
		return doList();
	}
	
	
	public Building getBuild() {
		return this.build;
	}

	public void setBuild(Building build) {
		this.build = build;
	}

	public Integer getBuildId() {
		return this.buildId;
	}

	public void setBuildId(Integer buildId) {
		this.buildId = buildId;
	}

	public PageBean<Building> getPage() {
		return this.page;
	}

	public void setPage(PageBean<Building> page) {
		this.page = page;
	}
}
